package ss.pku.jsa.type.constraint.solver;

public enum QError {
	INIT("Inferred qualifier contradicts initialization qualifier"), ASSIGN(
			"Assignment violates qualifier rules"), CAST(
			"Qualifier constraints established at cast"), CONSTR(
			"Inconsistent constraint created at constructor invocation"), INST(
			"Inconsistent constraint created at instantiation"), COND(
			"Inconsistent contraint created at conditional expression"), INFIX(
			"Inconsistent constraint generated at infix operation"), RETURN(
			"Inconsistent constraint created at return from method"), INVOKE(
			"Inconsistent constraint created at method invocation"), FIELD(
			"Inconsistent constraint generated at field access"), SPEC(
			"Violation of qualifier specified in JavaDoc"), INHERIT(
			"Violation of constraint between type and supertype"), INHERIT_PROP(
			"Violation of constraint between type and supertype, after propogation"), CLASS(
			"Violation of qualifier specified in ClassQType"), MERGE(
			"Same fields must have same types"), RECURSIVE(
			"Recursive types must have same qualifiers throughout"), FIELDPROP(
			"Field Propogation"),

	JAVARI("Assignment violates javari rules"), JAVARI_CONSERV(
			"Conservative assumption wrt readonly"), JAVARI_MUTABLE(
			"Violation of specified mutable qualifier"),

	FFI_OP_TRANSP("Operation results must be transparent"), FFI_NUM_TOO_LARGE(
			"Number literal too large to be ENUM considered transparent"), FFI_NUM_AS_ENUM(
			"Number literal interpreted as ENUM"), FFI_NUM_TRANSP(
			"Non-integer number literal is transparent"), FFI_CONST_TRANSP(
			"Constants are tranparent"), FFI_NEW_INST_TRANSP(
			"New instance must be transparent"), FFI_INFERRED(
			"Qualifier inferred from FFI"), FFI_SPECIAL_HANDLE(
			"Join 32bit & 64bit handle fields"), FFI_PUBLIC_METHOD(
			"Params of public methods are transparent"), FFI_PUBLIC_FIELD(
			"Public fields are transparent"),

	NON_INTERNED("Class defines .equals() method"), INTERNED(
			"Class used with =="), INHERITED_NONINTERNED(
			"equals method inherited from supertype"), INTERNED_INSTANCE(
			"Class instantiation point"), JAVARI_GLOBAL_HACK(
			"Shadow constraint for javari global hack");

	public final String msg;
	public final int num;

	private QError(String msg) {
		this.msg = msg;
		this.num = StaticNumberHolder.max;
		StaticNumberHolder.max += 1;
	}

	public static void registerQErrors() {
		int numMsgs = values().length;
		String[] contents = new String[numMsgs];
		for (QError qerr : values())
			contents[qerr.num] = qerr.msg;
		Native.register_messages(contents);
	}
}

class StaticNumberHolder {
	static int max = 0;
}